package warmachineroster.grapheditor.editpart;

import org.eclipse.gef.EditPart;
import org.eclipse.gef.EditPartFactory;

import warmachineroster.Roster;
import warmachineroster.RosterElement;
import warmachineroster.UnitRosterElement;
import warmachineroster.WarcasterRosterElement;
import warmachineroster.WarjackRosterElement;
import warmachinesystem.Solo;
import warmachinesystem.UnitAttachment;

public class WarmachineRosterEditpartFactory implements EditPartFactory {

	@Override
	public EditPart createEditPart(EditPart context, Object model) {
		EditPart ep = getEditPart(model);
		ep.setModel(model);
		return ep;
	}

	private EditPart getEditPart(Object model) {
		if(model instanceof Roster)
			return new RosterEditPart();
		if (model instanceof WarcasterRosterElement)
			return new WarcasterRosterElementEditPart();
		if (model instanceof WarjackRosterElement)
			return new WarjackRosterElementEditPart();
		if (model instanceof UnitRosterElement)
			return new UnitRosterElementEditPart();
		if (model instanceof RosterElement){
			RosterElement re = (RosterElement) model;
			if (re.getUnitType() instanceof UnitAttachment)
				return new UnitAttachmentRosterElementEditPart();
			else if (re.getUnitType() instanceof Solo)
				return new SoloRosterElementEditPart();
		}
		throw new RuntimeException(
				"Can't create part for model element: "
				+ ((model != null) ? model.getClass().getName() : "null"));
	}

}
